package com.ihd.ihardware.view.tzc.main.viewmodel;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.support.annotation.NonNull;

import com.ihd.ihardware.pojo.UpdateRes;
import com.ihd.ihardware.pojo.UserInfoRes;
import com.ihd.ihardware.view.tzc.main.model.BalanceRepository;

public class BalanceViewModel extends AndroidViewModel {

    private BalanceRepository mMainRepository;

    public BalanceViewModel(@NonNull Application application) {
        super(application);
    }

    public void report(String familyId) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.report(familyId);
    }

    public void getWeight(String familyId) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.getWeight(familyId);
    }

    public void getWeightTrends(String familyId) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.getWeightTrends(familyId);
    }

    public void members(UserInfoRes.DataBean ud, String memberId) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.members(ud, memberId);
    }

    public void registration(String registrationId) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.registration(registrationId);
    }

    public void checkUpdate() {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.update();
    }

    public void download(UpdateRes updateInfo) {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.download(updateInfo);
    }

    public void getUserInfo() {
        if (mMainRepository == null)
            mMainRepository = new BalanceRepository();
        mMainRepository.getUserInfo();
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        if (null != mMainRepository) {
            mMainRepository.onDestroy();
            mMainRepository = null;
        }
    }
}
